﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WebHttpApi.WebHttpApi.Core;

namespace WebHttpApi.WebHttpApi.HttpApi
{
    /// <summary>
    /// TYMeter 的摘要说明：第三方平台请求账户验证类
    /// </summary>
    public class TYMeter
    {
        #region 校验第三方接口登录账户名、密码，并返回 DepartmentId
        public static string DepartmentId(string UserName, string PassWord)
        {
            string str_result = "";

            string str_DepartmentId = "";
            string str_UserName = "";
            string str_Password = "";
            string str_PassSalt = "";

            string check_Password = "";

            string sql = "select DepartmentId,UserName,Password,PassSalt from v_Sys_Users where UserName='" + UserName + "'";
            System.Data.DataTable User_Department = WebSdkCore.select(sql);

            if (User_Department.Rows.Count > 0)
            {
                for (int i = 0; i < User_Department.Rows.Count; i++)
                {
                    str_DepartmentId = User_Department.Rows[i]["DepartmentId"].ToString();
                    str_UserName = User_Department.Rows[i]["UserName"].ToString();
                    str_Password = User_Department.Rows[i]["Password"].ToString();
                    str_PassSalt = User_Department.Rows[i]["PassSalt"].ToString();

                    check_Password = WebSdkCore.GetMD5(PassWord + str_PassSalt).ToUpper();
                    if (str_Password == check_Password)
                    {
                        str_result = str_DepartmentId;
                        break;
                    }
                    else
                    {
                        str_result = "000000";
                    }
                }
            }
            else
            {
                str_result = "000000";
            }
            return str_result;
        }
        #endregion 校验第三方接口登录账户名、密码，并返回 DepartmentId
    }
}